import pandas as pd
from datetime import datetime


def error5_idf(df,dict_info_setting ,columns):
    """
    检查'足背动脉搏动'列是否存在空项，标记紫色并添加批注

    :param df: 数据 DataFrame
    :param columns: 列名列表（仅包含 ['足背动脉搏动']）
    :return: (styles_info, comments_info) 样式和批注信息
    """
    styles_info = {}
    comments_info = []

    null_zu_yi = dict_info_setting["error5_idf"].split(':')[-1].strip()

    target_col = columns[0]  # 确保列名正确映射
    doctor_col = columns[1]

    for row_idx, row in df.iterrows():
        try:
            value1 = row[target_col]
            value2 = row[doctor_col]

            # 检查是否为空值（兼容 NaN、空字符串、None）
            if pd.isna(value1) or str(value1).strip() == '':
                # 标记紫色样式（对应 COLOR_SCHEME 的 'special'）
                styles_info[(row_idx, target_col)] = 'special'

                # 添加批注（直接标记在目标列）
                msg = "足背动脉搏动未填写，请检查"
                comments_info.append((row_idx, target_col, msg))

            # 检查是否为空值（兼容 NaN、空字符串、None）
            if pd.isna(value2) or str(value2).strip() == '':
                # 标记紫色样式（对应 COLOR_SCHEME 的 'special'）
                styles_info[(row_idx, doctor_col)] = 'special'

                # 添加批注（直接标记在目标列）
                msg = "随访医生签名为空，请检查"
                comments_info.append((row_idx, doctor_col, msg))

        except Exception as e:
            print(f"第 {row_idx + 2} 行处理失败: {str(e)}")
    if null_zu_yi == "True":
        return styles_info, comments_info
    else:
        return {}, []

